import {
	defineStore
} from 'pinia'
import {
	ref,
	computed
} from 'vue'

export default defineStore('msg', () => {

	const selectStartAddress = ref({})
	const selectEndAddress = ref({})
	const hotAddress = ref({})
	const currentOrderOther = ref({
		time: '',
		way: '',
		store: '',
		remark: '',
		totalPrice: 0,
		status: "等待司机接单",
		reason: ''
	})
	//当前展示的数据
	const currentOrder = computed(() => ({
		startAddress: selectStartAddress.value.address,
		endAddress: selectEndAddress.value.address,
		...currentOrderOther.value

	}))
	const resetCurrentOrder = () => {
		currentOrder.value = {
			id: '',
			startAddress: '',
			endAddress: '',
			time: '',
			way: '',
			store: '',
			remark: '',
			totalPrice: 0,
			status: "",
			reason: ''
		}
		selectStartAddress.value = {}
		selectEndAddress.value = {}
		hotAddress.value = {}
	}

	//修改status值
	const updateMessage = (key, item) => {
		currentOrder.value[key] = item
	}
	//修改selectStartAddress
	const updateStartAddress = (item) => {
		selectStartAddress.value = item
	}
	//修改selectEndAddress的值
	const updateEndAddress = (item) => {
		selectEndAddress.value = item
	}
	//修改hotAddress值
	const updateHotAddress = (item) => {
		hotAddress.value = item
	}
	const setCurrentOrder = (order) => {
		currentOrderOther.value = {
			...order
		}

	}

	return {
		selectStartAddress,
		selectEndAddress,
		hotAddress,
		currentOrder,
		resetCurrentOrder,
		updateMessage,
		updateStartAddress,
		updateEndAddress,
		updateHotAddress,
		setCurrentOrder
	}
})